package cn.dnui_zjq823.dnuifood_16110100823.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cn.dnui_zjq823.dnuifood_16110100823.R;
import cn.dnui_zjq823.dnuifood_16110100823.adapter.ShopAdapter;
import cn.dnui_zjq823.dnuifood_16110100823.bean.ShopBean;
import cn.dnui_zjq823.dnuifood_16110100823.listener.onRetrofitListener;
import cn.dnui_zjq823.dnuifood_16110100823.model.ShopModel;

/**
 * Created by dell on 2018/10/29.
 */

public class ShopFragment extends BaseFragment implements onRetrofitListener{
    private RecyclerView recycler_shop;
    private RecyclerView.LayoutManager layoutManager;
    private ShopAdapter shopAdapter;
    private List<ShopBean> list;

    @Override
    public void onSuccess(Object object, int flag) {
        if(flag==2) {
            list = (List) object;
            shopAdapter = new ShopAdapter(context);
            shopAdapter.setList(list);
            recycler_shop.setAdapter(shopAdapter);
        }
    }

    @Override
    public void onFalure(String msg) {
        Toast.makeText(context, "失败："+msg, Toast.LENGTH_SHORT).show();

    }

    public ShopFragment() {
        super();
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_shop, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initRecycleview(view);
        ShopModel model=new ShopModel();
        model.getAllShops(this);
    }

    private void initRecycleview(View view){
        recycler_shop=view.findViewById(R.id.recycler_shop);
        layoutManager=new LinearLayoutManager(context);
        recycler_shop.setLayoutManager(layoutManager);

    }
}
